package com.example.cushion.realize.setting;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.widget.NestedScrollView;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ScrollView;

import com.example.cushion.R;
import com.example.cushion.adapter.SettingAdapter;
import com.example.cushion.base.BaseFragment;
import com.example.cushion.binddata.DataMenuSetting;

import org.itzheng.and.baseutils.ui.UIUtils;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;

/**
 * Title:<br>
 * Description: <br>
 *
 * @email ItZheng@ZoHo.com
 * Created by itzheng on 2018-3-8.
 */
public class SettingFragment extends BaseFragment {
    View rootView;
    @BindView(R.id.rcvContent)
    RecyclerView rcvContent;
    Unbinder unbinder;
    @BindView(R.id.scrollView)
    NestedScrollView scrollView;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {
        if (rootView == null) {
            rootView = UIUtils.inflate(getActivity(), R.layout.fragment_setting);
        }
        unbinder = ButterKnife.bind(this, rootView);
        setAdapter();
        return rootView;
    }


    private void setAdapter() {
        //处理顶部自动上移的问题
        scrollView.setDescendantFocusability(android.view.ViewGroup.FOCUS_BLOCK_DESCENDANTS);
        rcvContent.setLayoutManager(new LinearLayoutManager(UIUtils.getContext()));
        rcvContent.setAdapter(new SettingAdapter(DataMenuSetting.getSettingGroup(getActivity())));

    }

    public static SettingFragment newFragment() {
        return new SettingFragment();
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder.unbind();
    }
}
